package com.akupilih.app;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListAdapter;
import android.widget.ListView;

import com.akupilih.app.adapter.CustomAdapter;
import com.akupilih.app.entity.E_Event;
import com.akupilih.app.helper.DateHelper;
import com.akupilih.app.model.DBClass;

public class EventFragment extends Fragment {
	public static final String KEY_TITLE = "title";
	public static final String KEY_DESC = "dekripsi";
	public static final String KEY_DATE = "date";

	private FragmentActivity myContext;
	ListView listView;
	List<E_Event> dataList;
	ArrayList<HashMap<String, Object>> postitem;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		View rootView = inflater.inflate(R.layout.fragment_pasangan, container,
				false);
		listView = (ListView) rootView.findViewById(R.id.listview);
		DBClass db = new DBClass(getActivity());
		dataList = db.selectEvent();
		setList(dataList);

		return rootView;
	}

	private void setList(List<E_Event> dataList2) {
		postitem = new ArrayList<HashMap<String, Object>>();
		if (dataList2 != null) {
			for (E_Event e : dataList2) {
				HashMap<String, Object> map = new HashMap<String, Object>();
				map.put(KEY_TITLE, e.getJudul());
				map.put(KEY_DATE, e.getTanggal_mulai());
				map.put(KEY_DESC, e.getDeskripsi());
				postitem.add(map);
			}
			ListAdapter adapter = new CustomAdapter(myContext, postitem,
					R.layout.row_lazy, new String[] { KEY_TITLE, KEY_DESC,
							KEY_DATE }, new int[] { R.id.head, R.id.body,
							R.id.foot });
			listView.setAdapter(adapter);
			listView.setDivider(null);
		}
	}

	@Override
	public void onAttach(Activity activity) {
		// TODO Auto-generated method stub
		super.onAttach(activity);
		myContext = (FragmentActivity) activity;

	}

}
